package com.cskaoyan.utils.backstage;

import com.cskaoyan.bean.vo.BaseRespVo;
import org.springframework.stereotype.Component;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

@Component
public class ValidateUtils {

    public static BaseRespVo validate(BindingResult result){
        FieldError fieldError = result.getFieldError();
        String field = fieldError.getField();
        Object rejectedValue = fieldError.getRejectedValue();
        String defaultMessage = fieldError.getDefaultMessage();
        return BaseRespVo.fail("请求参数" + field + "不合法；因为你传入了一个" +
                rejectedValue + ";" + defaultMessage);
    }

}
